import { inject, injectable } from 'inversify';
import { UsersRolesRepository } from '../data/users.roles.repository.ts';
import { roleItemMapper } from '../mappers/role.list.mapper.ts';
import { RoleItemModel } from '../models/role.detail.model.ts';

@injectable()
export class GetRoleDetailUseCase {
  constructor(
    @inject(RoleItemModel) private roleItemModel: RoleItemModel,
    @inject(UsersRolesRepository) private rolesRepository: UsersRolesRepository,
  ) {}

  async execute(_id: string) {
    try {
      this.roleItemModel.loading = true;
      const { data } = await this.rolesRepository.getRoleById(_id);

      this.roleItemModel.role = roleItemMapper(data);
    } finally {
      this.roleItemModel.loading = false;
    }
  }
}
